package com.zsrt.devbase.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyUtil {

	private Properties prop = null;
	
	public PropertyUtil(String propertyName) {
		InputStream inputstream = null;
		try {
			prop = new Properties();
			ClassLoader cl = PropertyUtil.class.getClassLoader();
			if (cl != null) {
				inputstream = cl.getResourceAsStream(propertyName);
			} else {
				inputstream = ClassLoader.getSystemResourceAsStream(propertyName);
			}
			prop.load(inputstream);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (null != inputstream) {
				try {
					inputstream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}

	}

	/**
	 * 读取数据
	 * 
	 * @param propertyName
	 * @param key
	 * @return
	 */
	public String getValueByKey(String key) {
		String result = "";
		try {
			result = prop.getProperty(key);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}
	
	/**
	 * 设置数据
	 * @author wujungang
	 * @param key
	 * @param value
	 * @return
	 */
	public Object setValueByKey(String key,String value){
		return prop.setProperty(key,  value);
	}
}